<?php
/*
 * print_r($_FILES);
 * //
 */
if (isset ( $_SESSION ['edit'] )) {
	$edit = $_SESSION ['edit'];
}

$liste_fichiersattaches = array ();
// echo getcwd();
if (isset ( $_FILES ['fichiersattaches'] ) and $_FILES ['fichiersattaches'] ['error'] == 0) {
	move_uploaded_file ( $_FILES ['fichiersattaches'] ['tmp_name'], $_SESSION ['pathway'] . $_SESSION ['pathway_js'] . '/uploads/' . basename ( $_FILES ['fichiersattaches'] ['name'] ) );
	chmod ( $_SESSION ['pathway'] . $_SESSION ['pathway_js'] . '/uploads/' . basename ( $_FILES ['fichiersattaches'] ['name'] ), 0777 );
	$fichiersattaches .= basename ( $_FILES ['fichiersattaches'] ['name'] ) . ";";
}

if (isset ( $_POST ['fichiersattachesoriginal_0'] )) {
	$fichiersattaches .= $_POST ['fichiersattachesoriginal_0'];
}

if (isset ( $_POST ['code1'] ) and $_POST ['code1'] != '') {
	$code1 = $_POST ['code1'];
}
if (isset ( $_POST ['code2'] ) and $_POST ['code2'] != '') {
	$code2 = $_POST ['code2'];
}
if (isset ( $_POST ['code3'] ) and $_POST ['code3'] != '') {
	$code3 = $_POST ['code3'];
}
if (isset ( $_POST ['code4'] ) and $_POST ['code4'] != '') {
	$code4 = $_POST ['code4'];
}
if (isset ( $_POST ['code5'] ) and $_POST ['code5'] != '') {
	$code5 = $_POST ['code5'];
}
if (isset ( $_POST ['codeexterne'] )) {
	$codeexterne = $_POST ['codeexterne'];
} else {
	$codeexterne = '';
}
if (isset ( $_POST ['codegenethon'] )) {
	$codegenethon = $_POST ['codegenethon'];
} else {
	$codegenethon = '';
}
if (isset ( $_POST ['centre'] ) and $_POST ['centre'] != '') {
	$centre = $_POST ['centre'];
	strtoupper ( $centre );
} else {
	$centre = '';
}
if (isset ( $_POST ['neurologist'] ) and $_POST ['neurologist'] != '') {
	$neurologist = $_POST ['neurologist'];
	$neurologist = strtoupper ( $neurologist );
} else {
	$neurologist = '';
}
if (isset ( $_POST ['datelinkage'] ) and $_POST ['datelinkage'] != '') {
	$datelinkage = $_POST ['datelinkage'];
} else {
	$datelinkage = '';
}
if (isset ( $_POST ['statut'] ) and $_POST ['statut'] != '') {
	$statut = $_POST ['statut'];
} else {
	$statut = '';
}
if (isset ( $_POST ['user'] ) and $_POST ['user'] != '') {
	$user = $_POST ['user'];
} else {
	$user = '';
}
if (isset ( $_POST ['locusteste'] ) and $_POST ['locusteste'] != '') {
	$locusteste = $_POST ['locusteste'];
} else {
	$locusteste = '';
}
if (isset ( $_POST ['haplotype'] ) and $_POST ['haplotype'] != '') {
	$haplotype = $_POST ['haplotype'];
} else {
	$haplotype = '';
} // cas ou l'on vient du modif_index
if (isset ( $_POST ['linkage'] ) and $_POST ['linkage'] != '') {
	$linkage = $_POST ['linkage'];
} else {
	$linkage = '';
}
if (isset ( $_POST ['lodscore'] ) and $_POST ['lodscore'] != '') {
	$lodscore = $_POST ['lodscore'];
} else {
	$lodscore = '';
}
if (isset ( $_POST ['commentairelinkage'] ) and $_POST ['commentairelinkage'] != '') {
	$commentairelinkage = $_POST ['commentairelinkage'];
	$commentairelinkage = mysql_real_escape_string ( $commentairelinkage );
} else {
	$commentairelinkage = '';
}
// ~ if(isset($_POST['commentairelinkage']) and $_POST['commentairelinkage'] != ''){ $commentairelinkage = $_POST['commentairelinkage']; $commentairelinkage = mysqli_real_escape_string($commentairelinkage);}else{ $commentairelinkage ='';}
if (isset ( $_POST ['fichiersattaches'] ) and $_POST ['fichiersattaches'] != '') {
	$fichiersattaches = $_POST ['fichiersattaches'];
} else {
	$fichiersattaches = '';
}
if (isset ( $_POST ['modelinkage'] ) and $_POST ['modelinkage'] != '') {
	$modelinkage = $_POST ['modelinkage'];
} else {
	$modelinkage = '';
}
if (isset ( $_POST ['diagnosticlinkage'] ) and $_POST ['diagnosticlinkage'] != '') {
	$diagnosticlinkage = $_POST ['diagnosticlinkage'];
} else {
	$diagnosticlinkage = '';
}
if (isset ( $_POST ['validation'] ) and $_POST ['validation'] != '') {
	$validation = $_POST ['validation'];
} else {
	$validation = '';
}
if (isset ( $_POST ['afaire'] ) and $_POST ['afaire'] != '') {
	$afaire = $_POST ['afaire'];
	$afaire = mysql_real_escape_string ( $afaire );
} else {
	$afaire = '';
}
if (isset ( $_POST ['commentairesconclusion'] )) {
	$commentairesconclusion = $_POST ['commentairesconclusion'];
	$commentairesconclusion = mysql_real_escape_string ( $commentairesconclusion );
} else {
	$commentairesconclusion = '';
}

if (isset ( $_GET ['edit'] )) {
	$edit = $_GET ['edit'];
	$update = "UPDATE `$db`.`linkage` SET 
	`code1` = '$code1',
	`code2` = '$code2',
	`code3` = '$code3',
	`code4` = '$code4',
	`codeexterne` = '$codeexterne',
	`codegenethon` = '$codegenethon',
	`centre` = '$centre',
	`neurologist` = '$neurologist',
	`modelinkage` = '$modelinkage',
	`locusteste` = '$locusteste',
	`haplotype` = '$haplotype',
	`linkage` = '$linkage',
	`lodscore` = '$lodscore',
	`commentairelinkage` = '$commentairelinkage',
	`date` = '$date',
	`statut` = '$statut',
	`user` = '$user',
	`fichiersattaches` = '$fichiersattaches',
	`diagnosticlinkage` = '$diagnosticlinkage',
	`afaire` = '$afaire',
	`validation` = '$validation',
	`commentairesconclusion` = '$commentairesconclusion'
	WHERE `linkage`.`index` = '$edit';";
	// echo $update;
	mysql_query ( $update ) or die ( "Can't modify entry : " . mysql_error () );
	$_POST = array ();
} else {
	$recupereindexmaxlinkage = "select MAX(`index`) FROM `linkage`";
	$resultindex = mysql_query ( $recupereindexmaxlinkage ) or die ( "Impossible de r&eacute;cup&eacute;rer l'index de la table linkage" );
	while ( $ligne = mysql_fetch_row ( $resultindex ) ) {
		$indexlinkage = $ligne [0] + 1;
	}
	$insertlinkage = "INSERT INTO `$db`.`linkage` (`index`, `code1`, `code2`, `code3`, `code4`, `codeexterne`, `codegenethon`,`centre`, `neurologist`, `modelinkage`, `locusteste`, `haplotype`,`linkage`, `lodscore`, `commentairelinkage`, `date`, `statut`, `user`, `fichiersattaches`, `diagnosticlinkage`, `afaire`, `validation`, `commentairesconclusion`) VALUES ('$indexlinkage','$code1', '$code2','$code3','$code4','$codeexterne', '$codegenethon','$centre', '$neurologist', '$modelinkage', '$locusteste', '$haplotype','$linkage', '$lodscore', '$commentairelinkage', '$datelinkage', '$statut', '$user', '$fichiersattaches', '$diagnosticlinkage', '$afaire', '$validation', '$commentairesconclusion');";
	mysql_query ( $insertlinkage ) or die ( "Impossible d'ins&eacute;rer donn&eacute;es dans table linkage : " . mysql_error () );
	// echo $insertlinkage;
}
$_POST = array ();

?>
